package org.example.test5.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.example.test5.model.Card;
import java.util.List;

@Mapper
public interface CardMapper {
    //根据id查询名片
    @Select("select * from card where id = #{id}")
    Card findCardById(int id);

    //添加名片
    @Insert("insert into card(name,telephone,email,company,post,address,logo_name,user_id)" +
            " values(#{name},#{telephone},#{email},#{company},#{post},#{address},#{logoName},#{userId})")
    void insertCard(Card card);

    //修改名片
    @Select("update card set name = #{name},telephone = #{telephone},email = #{email},company = #{company}," +
            "post = #{post},address = #{address},logo_name = #{logoName},user_id = #{userId} where id = #{id}")
    void updateCard(Card card);

    //删除名片
    @Select("delete from card where id = #{id}")
    void deleteCard(int id);

    //查询所有名片
    @Select("select * from card")
    List<Card> findAll();

    //根据名片名查询用户id
    @Select("SELECT user_id FROM card WHERE name = #{name}")
    Integer getUserIdByName(String name);
}